package net.wanho.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class ResourcesConfig implements WebMvcConfigurer {
    /**
     * 本地文件上传路径
     */
    @Value("${file.path}")
    private String localFilePath;

    /**
     * 本地文件访问前缀
     */
    @Value("${file.prefix}")
    public String localFilePrefix;

    /**
     * 本地文件上传路径的映射
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler(localFilePrefix + "/**")
                .addResourceLocations("file:" + localFilePath + File.separator);
    }
}